package com.prik.strategy.discount;

import com.prik.strategy.discount.strategies.OrdinaryDiscountStrategy;
import com.prik.strategy.discount.strategies.PartnerDiscountStrategy;
import com.prik.strategy.discount.strategies.VipDiscountStrategy;
import com.prik.strategy.discount.pojo.Customer;

import java.util.HashMap;
import java.util.Map;

/**
 * 策略工厂
 * 单例
 *
 * @author prik
 * @date 2019/7/18
 */
public class DiscountStrategyFactory {

    /**
     * private修饰的构造函数，防止使用者手动创建
     */
    private DiscountStrategyFactory() {
    }

    private static DiscountStrategyFactory factory = new DiscountStrategyFactory();

    private static Map<Integer, DiscountStrategy> strategyMap = new HashMap();

    static {
        strategyMap.put(Customer.TYPE_ORDINARY, new OrdinaryDiscountStrategy());
        strategyMap.put(Customer.TYPE_VIP, new VipDiscountStrategy());
        strategyMap.put(Customer.TYPE_PARTNER, new PartnerDiscountStrategy());
    }

    public DiscountStrategy creator(int customerType) {
        return strategyMap.get(customerType);
    }

    public static DiscountStrategyFactory getInstance() {
        return factory;
    }
}
